/**
 *  角色数据管理模块
 */
import axios from "../../utils/axios"

export default {
    namespaced: true,
    state: {
        roleList: []
    },
    mutations: {
        initRoleListMutations(state,list) {
            state.roleList = list
        }
    },
    actions: {
        initRoleListActions({commit}) {
            axios.get("/rolelist").then(response => {
                // console.log(response);
                commit("initRoleListMutations",response.list)
            })
        },
        addRoleListActions({dispatch},role) {
            // 异步请求添加数据
            axios.post("/roleadd",role).then(response => {
                console.log(response);
                if(response.code===200) {
                    // 同步前后台数据
                    dispatch("initRoleListActions")
                }
            })
        },
        editRoleListActions({dispatch},role) {
            // 异步请求添加数据
            axios.post("/roleedit",role).then(response => {
                if(response.code === 200) {
                    // 同步前后台数据
                    dispatch("initRoleListActions")
                }
            })
        },
        deleteRoleListActions({dispatch},id) {
            // 异步请求添加数据
            axios.post("/roledelete",{id}).then(response => {
                if(response.code === 200) {
                    dispatch("initRoleListActions")
                }
            })
        }
    },
    getters: {}
}